package com.mall.bargain.service.impl;

import com.mall.bargain.mapper.BargainingRecordMapper;
import com.mall.bargain.service.BargainingRecordService;
import com.mall.bargain.vo.*;
import com.mall.common.response.CommonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 砍价记录业务处理
 * @author LiJinYang
 * @version 1.0
 * @email 283006176@qq.com
 * @date 2021/07/20 14:14
 */
@Service
public class BargainingRecordServiceImpl implements BargainingRecordService {
    @Autowired
    private BargainingRecordMapper bargainingRecordMapper;

    /**
     * 查询每个用户已有的砍价商品
     * @param uid
     * @return
     */
    @Override
    public CommonResponse findAll(Long uid) {
        if(uid==null){
            return new CommonResponse(-1,"参数不能为空",null);
        }else {
            List<BargainingList> all = bargainingRecordMapper.findAll(uid);
            if(all.size()>0){
                return new CommonResponse(0,"操作成功",all);
            }else {
                return new CommonResponse(-1,"操作失败",all);
            }
        }

    }

    /**
     * 查询每个用户已有的砍价商品对应的详情
     * @param id
     * @return
     */
    @Override
    public CommonResponse findById(Long id) {
        if(id==null){
            return new CommonResponse(-1,"参数不能为空",null);
        }else {
            List<BargainDetails> list = bargainingRecordMapper.findById(id);
            if(list.size()>0){
                list.stream().forEach(bargainDetails -> {
                    bargainDetails.setFriendsBargainList(bargainingRecordMapper.findByUserId(bargainDetails.getId()));
                });
                return new CommonResponse(0,"操作成功",list);
            }else {
                return new CommonResponse(-1,"操作失败",list);
            }
        }
    }

    /**
     * 用户砍价详情
     * @param id
     * @return
     */
    @Override
    public CommonResponse seeDetails(Integer id) {
        if(id==null){
            return new CommonResponse(-1,"参数不能为空",null);
        }else {
            List<BargainUser> bargainUsers = bargainingRecordMapper.seeDetails(id);
            if(bargainUsers.size()>0){

                return new CommonResponse(0,"操作成功",bargainUsers);
            }else {
                return new CommonResponse(-1,"操作失败",bargainUsers);
            }
        }
    }

    /**
     * 获取用户个人的砍价记录
     * 砍价活动ID
     * @param id
     * @return
     */
    @Override
    public CommonResponse record(Integer id) {
        if(id==null){
            return new CommonResponse(-1,"参数不能为空",null);
        }else {
            List<Record> record = bargainingRecordMapper.record(id);
            if(record.size()>0){

                return new CommonResponse(0,"操作成功",record);
            }else {
                return new CommonResponse(-1,"操作失败",record);
            }
        }
    }

    /**
     * 我的订单中展示代发货商品
     * @param id
     * @param status
     * @return
     */
    @Override
    public CommonResponse myOrder(Integer id, String status) {
        if(id==null){
            return new CommonResponse(-1,"参数不能为空",null);
        }else {
            List<MyOrder> myOrders = bargainingRecordMapper.myOrder(id, status);
            if(myOrders.size()>0){

                return new CommonResponse(0,"操作成功",myOrders);
            }else {
                return new CommonResponse(-1,"操作失败",myOrders);
            }
        }
    }
}
